from langchain_community.llms import HuggingFacePipeline
from langchain.prompts import PromptTemplate
from langchain_core.prompts import ChatPromptTemplate
import gradio as gr 
from langchain_core.prompts import ChatPromptTemplate  
from langchain.prompts import PromptTemplate 
from langchain_core.output_parsers import StrOutputParser
from langchain_community.llms import HuggingFacePipeline
from langchain_core.prompts.chat import AIMessagePromptTemplate
from langchain.prompts import HumanMessagePromptTemplate 


hf = HuggingFacePipeline.from_model_id(
    model_id="THUDM/chatglm3-6b",
    task="text-generation",
    verbose=True,
    device=0,
    model_kwargs={"trust_remote_code":True},
    pipeline_kwargs={"max_new_tokens": 5000},
)


# from ChatGLM_new import zhipu_llm

# hf  = zhipu_llm 

prompt = ChatPromptTemplate.from_messages([
        HumanMessagePromptTemplate.from_template("深圳的天气怎么样"),
        AIMessagePromptTemplate.from_template("深圳今天的天气非常好"),
           HumanMessagePromptTemplate.from_template("最近有什么好看的电影"),
        AIMessagePromptTemplate.from_template("非诚勿扰不错"),
           HumanMessagePromptTemplate.from_template("{user_input}"),
            ])

chain = prompt | hf

def greet2(name):
    response = chain.invoke({"user_input": name})
    return response

def alternatingly_agree(message, history):
   return greet2(message)

gr.ChatInterface(alternatingly_agree).launch()

